package com.jerry.cui.dingtalk;

import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiDepartmentListRequest;
import com.dingtalk.api.request.OapiGettokenRequest;
import com.dingtalk.api.request.OapiUserCountRequest;
import com.dingtalk.api.request.OapiUserListadminRequest;
import com.dingtalk.api.response.OapiDepartmentListResponse;
import com.dingtalk.api.response.OapiGettokenResponse;
import com.dingtalk.api.response.OapiUserCountResponse;
import com.dingtalk.api.response.OapiUserListadminResponse;
import com.taobao.api.ApiException;

public class test {
	public static void main(String[] args) {
        try {
        	DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken");
        	OapiGettokenRequest request = new OapiGettokenRequest();
        	request.setAppkey("dingauzuyqudj83jeqav");
        	request.setAppsecret("IcrA7Tz3wlwPw_fhwHKVCJoG-Te1yNlFfaIMTsSqoWCO_iJbMZLuFKI5I7-BBajX");
        	request.setHttpMethod("GET");
        	OapiGettokenResponse response = client.execute(request);
        	String accessToken = response.getAccessToken();
        	System.out.println(accessToken);
        	
        	
        	DingTalkClient client1 = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/user/count");
        	OapiUserCountRequest req = new OapiUserCountRequest();
        	req.setOnlyActive(false);
        	OapiUserCountResponse rsp = client1.execute(req, accessToken);
        	System.out.println(rsp.getBody());
        	
        	DingTalkClient client2 = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/user/listadmin");
        	OapiUserListadminRequest req2 = new OapiUserListadminRequest();
        	OapiUserListadminResponse rsp2 = client2.execute(req2, accessToken);
        	System.out.println(rsp2.getBody());
        	
                DingTalkClient client3 = new DefaultDingTalkClient("https://oapi.dingtalk.com/department/list");
    			OapiDepartmentListRequest req3 = new OapiDepartmentListRequest();
    			req3.setHttpMethod("GET");
    			OapiDepartmentListResponse rsp3 = client3.execute(req3, "ca2dd875e7e83fe893bc3f2c654545e3");
    			System.out.println(rsp3.getBody());
        	
        } catch (ApiException e) {
            e.printStackTrace();
        }
    }
}
